package group.program.register.full_name;

import group.program.Controller.RegisterController;
import group.program.Service.RegisterService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.mockito.Mockito.when;

class exist {

    @InjectMocks
    private RegisterController registerController;

    @Mock
    private RegisterService registerService; // 创建一个对 RegisterService 的 mock 实例

    @BeforeEach
    void setUp() {
        MockitoAnnotations.openMocks(this);
    }

    @Test
    void testExistFullName() {
        String existFullName = "马嘉祺";

        // 模拟 registerService 中的方法
        when(registerService.isFullNameExist(existFullName)).thenReturn("真实姓名已存在");

        assertEquals("真实姓名已存在", registerController.checkIfFullNameExists(existFullName));
    }

    @Test
    void testNoExistFullName() {
        String noExistFullName = "测试";

        // 模拟 registerService 中的方法
        when(registerService.isFullNameExist(noExistFullName)).thenReturn(null);

        assertNull(registerController.checkIfUserNameExists(noExistFullName));
    }
}
